package com.example.admin.service.imp;

import com.alibaba.fastjson.JSONObject;
import com.example.admin.base.PageResponse;
import com.example.admin.bean.LoginUserDetails;
import com.example.admin.bean.NursingProject;
import com.example.admin.mapper.NursingProjectmapper;
import com.example.admin.service.NursingProjectservice;
import com.example.admin.utils.UserThreadLocal;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ImpNursingProject implements NursingProjectservice {
    @Autowired
    NursingProjectmapper nursingProjectmapper;

    @Override
    public PageResponse<NursingProject> searchingforlist(Integer pagenum, Integer pagesize, NursingProject nursingProject) {
        PageHelper.startPage(pagenum,pagesize);
        List<NursingProject> projectlist = nursingProjectmapper.searchingforlist(nursingProject);
        Page page = (Page) projectlist;
        PageResponse<NursingProject> objectPageResponse = new PageResponse<NursingProject>(page);
        objectPageResponse.setRecords(projectlist);
        return objectPageResponse;

    }

    @Override
    public Integer save(NursingProject nursingProject) {
        String subject = UserThreadLocal.getSubject();
        LoginUserDetails loginUserDetails = JSONObject.parseObject(subject, LoginUserDetails.class);
        Long userId = loginUserDetails.getId();
        nursingProject.setCreateBy(userId);
        return nursingProjectmapper.save(nursingProject);
    }

    @Override
    public NursingProject findbyid(Long id) {
       NursingProject nursingProject =  nursingProjectmapper.findbyid(id);
       return nursingProject;
    }

    @Override
    public Integer edit(NursingProject nursingProject) {
       Integer num =  nursingProjectmapper.edit(nursingProject);
       return num;
    }

    @Override
    public Integer fixstatus(Long id, Integer status) {
       Integer successnum = nursingProjectmapper.fixstatus(id,status);
       return successnum;
    }

    @Override
    public Integer delete(Long id) {
       return nursingProjectmapper.delete(id);
    }
}
